var a = getApp();

Page({
    data: {
        active: "",
        list: [],
        base_data: {},
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(a) {
        this.initData(), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    onChange: function(a) {
        1 === a.detail.index ? this.setData({
            active: "0"
        }) : 2 === a.detail.index ? this.setData({
            active: "1"
        }) : 3 === a.detail.index ? this.setData({
            active: "-1"
        }) : this.setData({
            active: ""
        }), this.initData(), this.getData();
    },
    initData: function() {
        this.setData({
            list: [],
            page: 1,
            total_page: 0,
            isLoadMore: !0
        });
    },
    getData: function() {
        var t = this, e = {
            status: this.data.active,
            page: 1
        }, s = a.getNetAddresss("plugin.consume-red-packet.Frontend.Modules.Receive.Controllers.records.index");
        a._getNetWork({
            url: s,
            data: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    base_data: e.data.base_data,
                    list: e.data.page_list.data,
                    total_page: e.data.page_list.last_page,
                    isLoadMore: !0
                }), t.data.total_page <= 1 && t.setData({
                    isLoadMore: !1
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.data.page >= this.data.total_page) t.setData({
            isLoadMore: !1
        }); else {
            t.setData({
                page: this.data.page + 1
            });
            var e = {
                status: this.data.active,
                page: this.data.page
            }, s = a.getNetAddresss("plugin.consume-red-packet.Frontend.Modules.Receive.Controllers.records.index");
            a._getNetWork({
                url: s,
                data: e,
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? t.setData({
                        total_page: e.data.page_list.last_page,
                        list: t.data.list.concat(e.data.page_list.data),
                        isLoadMore: !0
                    }) : t.setData({
                        page: t.data.page - 1,
                        isLoadMore: !1
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    }
});